public class Test {

    public static MySingleList.ListNode mergeTwoLists(MySingleList.ListNode list1,
                                               MySingleList.ListNode list2) {
        MySingleList.ListNode newHead = new MySingleList.ListNode(-1);
        MySingleList.ListNode tmp = newHead;
        while(list1 != null && list2 != null){
            if (list1.val < list2.val){
                tmp.next = list1;
                list1 = list1.next;
                tmp = tmp.next;
            }else {
                tmp.next = list2;
                list2 = list2.next;
                tmp = tmp.next;
            }
        }
        if (list1 != null){
            tmp.next = list1;
        }
        if (list2 != null){
            tmp.next = list2;
        }
        return  newHead.next;
    }


    public static void main(String[] args) {
        MySingleList.ListNode mySingleList = new MySingleList.ListNode(1);
        MySingleList.ListNode mySingleList1 = new MySingleList.ListNode(2);
        MySingleList.ListNode mySingleList2 = new MySingleList.ListNode(6);
        MySingleList.ListNode mySingleList3 = new MySingleList.ListNode(7);
        mySingleList.next = mySingleList1;
        mySingleList1.next = mySingleList2;
        mySingleList2.next = mySingleList3;


        MySingleList.ListNode mySingleList4 = new MySingleList.ListNode(3);
        MySingleList.ListNode mySingleList5 = new MySingleList.ListNode(4);
        MySingleList.ListNode mySingleList6 = new MySingleList.ListNode(8);
        MySingleList.ListNode mySingleList7 = new MySingleList.ListNode(9);
        MySingleList.ListNode mySingleList9 = new MySingleList.ListNode(11);
        mySingleList4.next = mySingleList5;
        mySingleList5.next = mySingleList6;
        mySingleList6.next = mySingleList7;
        mySingleList7.next = mySingleList9;

        MySingleList.ListNode head = mergeTwoLists(mySingleList,mySingleList4);
        System.out.println(head);
    }

    public static void main2(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addFirst(0);
        mySingleList.addFirst(1);
        mySingleList.addFirst(2);
        mySingleList.addFirst(3);
        mySingleList.addFirst(4);

        mySingleList.display();

        mySingleList.reverseList();
        mySingleList.display();
    }

    public static void main1(String[] args) {
        MySingleList mySingleList = new MySingleList();
        //mySingleList.creatList();

        mySingleList.addFirst(0);
        mySingleList.addFirst(1);
        mySingleList.addFirst(2);
        mySingleList.addFirst(3);
        mySingleList.addFirst(4);

        mySingleList.display();
        mySingleList.addIndex(0,5);
        mySingleList.addIndex(0,5);
        mySingleList.addIndex(0,5);

        mySingleList.display();

        mySingleList.removeAllKey(5);
        mySingleList.display();
    }
}
